<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>首页</title>
</head>
<body>
    <h1>首页</h1>
    <div id="wel">
        欢迎你！
    </div>
    <a href="###" id="quit">退出</a>
    <a href="###" id="login">登陆</a>
</body>
<script src="../common.js"></script>
<script>
    (function() {

        let wel = document.getElementById('wel');
        let quit = document.getElementById('quit');
        let login = document.getElementById('login');

        /*
            需求：
                1.获取账号显示到页面；(从cookie读取)
                2.点击退出：删除cookie
                3.点击登陆，跳转到登陆页面，记录url地址

        */

        //1.获取账号显示到页面；(从cookie读取)
        let name = getCookie('name');
        wel.innerHTML = name + '欢迎你!';

        //2.点击退出：删除cookie
        quit.onclick = () => {
            removeCookie('name');
            wel.innerHTML = '欢迎你!';
        }

        //3.点击登陆，跳转到登陆页面，记录url地址
        login.onclick = () => {
            setCookie('url',location.href,1);
            location.href = '06login.html';
        }

        // console.log(name);

    })();
</script>
</html>